<?php

namespace App\Http\Livewire;

use App\Models\Domain as DomainModel;
use Livewire\Component;

class DomainList extends Component
{
    public $searchString;
    public $domainList;

    public function mount()
    {
        $this->domainList = DomainModel::all();
    }

    public function updatedSearchString()
    {
        if ($this->searchString !== '') {
            $this->domainList = DomainModel::where('name', 'like', '%' . $this->searchString . '%')->get();

            return;
        }

        $this->domainList = DomainModel::all();
    }

    public function render()
    {
        return view('livewire.domain.domain-list');
    }
}
